package com.yigang.homecontroller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.yigang.entity.Orderdetails;
import com.yigang.entity.PayMent;
import com.yigang.entity.User;
import com.yigang.service.AlipayService;
import com.yigang.utils.ResultUtil;
import com.yigang.utils.UserConst;

@Controller
@RequestMapping("/alipay")
public class AlipayController {
	@Autowired
	AlipayService aliPayService;
	@RequestMapping("/zhifu")
		public String Alipay(Model model,HttpServletRequest request, HttpSession session) {
			Object attribute = session.getAttribute(UserConst.LOGIN_USER_INFO);
	        if (null != attribute) {
	            User user = JSON.parseObject((String) attribute, User.class);
	            if (user != null) {
	                List<Map<String, Object>> fukuanjine = aliPayService.alipayselect();		
	                
	        		System.out.println(fukuanjine);
	        		session.setAttribute("fukuanjine", fukuanjine);
	        		
//	        		model.addAttribute("alipay", alipay);
	                
	        		return "/index";
	            }
	            return "jsp/userLogin";
	        }
	        return "jsp/userLogin";
	    }
	@RequestMapping("/addPay")
    @ResponseBody
    public ResultUtil addPay(Orderdetails order, HttpServletRequest request, HttpSession session) {
        Object attribute = session.getAttribute(UserConst.LOGIN_USER_INFO);
        if (null != attribute) {
            User user = JSON.parseObject((String) attribute, User.class);
           
            
            
            int i = aliPayService.addPay(order);
             if (i > 0) {
                return ResultUtil.ok(1);
            } else {
                return ResultUtil.error("订单创建失败");
            }
        } else {
            return ResultUtil.error("请先登录");
        }
    }
}
